package com.hzeport.bgs22emduty.inbound.api;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.hzeport.bgs22emduty.entity.ScreenDutyNoticeList;
import com.masa.common.core.base.BaseResult;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import com.masa.common.log.annotation.SysLog;
import com.hzeport.bgs22emduty.entity.ScreenEmergencyPlan;
import com.hzeport.bgs22emduty.service.ScreenEmergencyPlanService;
//import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * ${comments}
 *
 * @author code generator
 * @date 2023-02-14 09:39:44
 */
@RestController
@AllArgsConstructor
@RequestMapping("/screenemergencyplan")
@Api(value = "screenemergencyplan", tags = "${comments}管理")
@Slf4j
public class ScreenEmergencyPlanController {

    private final ScreenEmergencyPlanService screenEmergencyPlanService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param screenEmergencyPlan ${comments}
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public BaseResult getScreenEmergencyPlanPage(Page page, ScreenEmergencyPlan screenEmergencyPlan) {
        return BaseResult.ok(screenEmergencyPlanService.page(page, screenEmergencyPlan));
    }


    /**
     * 通过id查询${comments}
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    public BaseResult getById(@PathVariable("id") String id) {
        return BaseResult.ok(screenEmergencyPlanService.getById(id));
    }

    /**
     * 新增${comments}
     * @param screenEmergencyPlan ${comments}
     * @return R
     */
    @ApiOperation(value = "新增${comments}", notes = "新增${comments}")
    //@SysLog(.*)
    @PostMapping
    public BaseResult save(@RequestBody ScreenEmergencyPlan screenEmergencyPlan) {
        return BaseResult.ok(screenEmergencyPlanService.save(screenEmergencyPlan));
    }

    /**
     * 修改${comments}
     * @param screenEmergencyPlan ${comments}
     * @return R
     */
    @ApiOperation(value = "修改${comments}", notes = "修改${comments}")
    //@SysLog(.*)
    @PutMapping
    public BaseResult updateById(@RequestBody ScreenEmergencyPlan screenEmergencyPlan) {
        String id = screenEmergencyPlan.getId();
        if (StringUtils.isNotBlank(id)) {
            ScreenEmergencyPlan byId = screenEmergencyPlanService.getById(id);
            if (byId != null){
                screenEmergencyPlan.setRecVersion(byId.getRecVersion());
            }
        }
        return BaseResult.ok(screenEmergencyPlanService.updateById(screenEmergencyPlan));
    }

    /**
     * 通过id删除${comments}
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除${comments}", notes = "通过id删除${comments}")
    //@SysLog(.*)
    @DeleteMapping("/{id}")
    public BaseResult removeById(@PathVariable String id) {
        return BaseResult.ok(screenEmergencyPlanService.removeById(id));
    }

}
